package com.gitee.vo;

import cn.hutool.http.HttpStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.gitee.enums.ResponseEnum;
import lombok.Data;

@Data
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ResponseVo<T> {

    private Integer code;

    private String msg;

    private T data;

    public ResponseVo(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseVo(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseVo(Integer code, T data) {
        this.code = code;
        this.data = data;
    }


    public static <T> ResponseVo<T> ok(T data) {
        return new ResponseVo<>(HttpStatus.HTTP_OK, data);
    }

    public static <T> ResponseVo<T> ok(ResponseEnum responseEnum, T data) {
        return new ResponseVo<>(HttpStatus.HTTP_OK, responseEnum.getDesc(), data);
    }

    public static <T> ResponseVo<T> ok(String msg, T data) {
        return new ResponseVo<>(HttpStatus.HTTP_OK, msg, data);
    }

    public static <T> ResponseVo<T> ok(ResponseEnum responseEnum) {
        return new ResponseVo<>(HttpStatus.HTTP_OK, responseEnum.getDesc());
    }

    public static <T> ResponseVo<T> error(ResponseEnum responseEnum) {
        return new ResponseVo<>(HttpStatus.HTTP_INTERNAL_ERROR, responseEnum.getDesc());
    }

    public static <T> ResponseVo<T> error(String msg) {
        return new ResponseVo<>(HttpStatus.HTTP_INTERNAL_ERROR, msg);
    }

    public static <T> ResponseVo<T> error(Integer code, ResponseEnum responseEnum) {
        return new ResponseVo<>(code, responseEnum.getDesc());
    }

    public static <T> ResponseVo<T> error(Integer code, String msg) {
        return new ResponseVo<>(code, msg);
    }

}
